package com.fucius.study.leetcode;

import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.stream.Collectors;

public class CompareVersion {
    public boolean possiblyEquals(String s1, String s2) {
        int i=0,j=0,m=s1.length(),n=s2.length();
        int aNum = 0;
        int bNum = 0;

        labe1:
        while((i<m && j<n) ||(aNum>0 || bNum>0)){
            char a = i==m?'*':s1.charAt(i++),b=j==n?'*':s2.charAt(j++);
            if(aNum > 0){
                a = '*';
                aNum--;
            }
            if(bNum > 0){
                b = '*';
                bNum--;
            }
            if(a>'0' && a <='9'){
                aNum = a -'0';
                while(i<m){
                    if( s1.charAt(i) >= '0' && s1.charAt(i) <='9'){
                        aNum = 10*aNum + (s1.charAt(i) - '0');
                        i++;
                    }else{
                        continue labe1;
                    }

                }
            }
            if(b>'0' && b <='9'){
                bNum = b -'0';
                while(j<n){
                    if( s2.charAt(j) >= '0' && s2.charAt(j) <='9'){
                        bNum = 10*bNum + (s2.charAt(j) - '0');
                        j++;
                    }else{
                        continue labe1;
                    }
                }
            }

            if(a=='*' || b== '*'){
                continue;
            }
            if(a!=b){
                return false;
            }
        }
        if(i!=m || j!=n){
            return false;
        }
        return true;
    }

    public static void main(String[] args) {
        System.out.println(new CompareVersion().possiblyEquals("internationalization12","i18n11n"));
    }
}

